package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.vo.WebsiteCategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.WebsiteCategory;
import com.ruoyi.system.service.IWebsiteCategoryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * websiteCategoryController
 * 
 * @author ruoyi
 * @date 2023-09-28
 */
@RestController
@RequestMapping("/category")
public class WebsiteCategoryController extends BaseController
{
    @Autowired
    private IWebsiteCategoryService websiteCategoryService;

    /**
     * 查询websiteCategory列表
     */
    @RequiresPermissions("system:category:list")
    @GetMapping("/getList")
    public R<List<WebsiteCategoryVo>> getList(WebsiteCategory websiteCategory)
    {
        return R.ok(
                websiteCategoryService.selectWebsiteCategoryAndInfoList(websiteCategory)
        );
    }

    /**
     * 查询websiteCategory列表
     */
    @RequiresPermissions("system:category:list")
    @GetMapping("/list")
    public TableDataInfo list(WebsiteCategory websiteCategory)
    {
        startPage();
        List<WebsiteCategory> list = websiteCategoryService.selectWebsiteCategoryList(websiteCategory);
        return getDataTable(list);
    }



    /**
     * 导出websiteCategory列表
     */
    @RequiresPermissions("system:category:export")
    @Log(title = "websiteCategory", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WebsiteCategory websiteCategory)
    {
        List<WebsiteCategory> list = websiteCategoryService.selectWebsiteCategoryList(websiteCategory);
        ExcelUtil<WebsiteCategory> util = new ExcelUtil<WebsiteCategory>(WebsiteCategory.class);
        util.exportExcel(response, list, "websiteCategory数据");
    }

    /**
     * 获取websiteCategory详细信息
     */
    @RequiresPermissions("system:category:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(websiteCategoryService.selectWebsiteCategoryById(id));
    }

    /**
     * 新增websiteCategory
     */
    @RequiresPermissions("system:category:add")
    @Log(title = "websiteCategory", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WebsiteCategory websiteCategory)
    {
        return toAjax(websiteCategoryService.insertWebsiteCategory(websiteCategory));
    }

    /**
     * 修改websiteCategory
     */
    @RequiresPermissions("system:category:edit")
    @Log(title = "websiteCategory", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WebsiteCategory websiteCategory)
    {
        return toAjax(websiteCategoryService.updateWebsiteCategory(websiteCategory));
    }

    /**
     * 删除websiteCategory
     */
    @RequiresPermissions("system:category:remove")
    @Log(title = "websiteCategory", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(websiteCategoryService.deleteWebsiteCategoryByIds(ids));
    }
}
